home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10005 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  65 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.sprintlink.net!mv!usenet
  3. From: ENGR@GSSI.MV.COM (Michael Furman)
  4. Subject: Re: how slow are virtual functions?
  5. Message-ID: <DnLFGx.Bxr@mv.mv.com>
  6. Mime-Version: 1.0
  7. Organization: GSSI
  8. Date: Fri, 1 Mar 1996 14:41:20 GMT
  9. References: <4gioqc$9f0@onlink3.onlink.net> <31344ACF.1ABB@bbn.hp.com>
  10. X-Newsreader: WinVN 0.93.10
  11. X-Nntp-Posting-Host: gssi.mv.com
  12.  
  13. In article <31344ACF.1ABB@bbn.hp.com>, Manfred_Lange@bbn.hp.com says...
  14. >
  15. >wfss16@onlink.net wrote:
  16. > ..... snip
  17. >You will have a runtime overhead, that is caused by the fact the address of 
  18. a vi
  19. >rtual 
  20. >function is determined during runtime. Each class has a address table 
  21. (vtable) w
  22. >hich 
  23. >also contains the address of all virtual functions declared and defined for 
  24. that
  25. >class. The runtime system has to look up the correct address depending on 
  26. the ty
  27. >pe of 
  28. >the object (the class the object is an instance of) and then calls the 
  29. function.
  30. > This 
  31. >mechanism is also known as late binding.
  32. >For non-virtual functions, the binding can be done during link-time. This 
  33. means 
  34. >that 
  35. >no additional code has to be executed by the runtime-environment to 
  36. determine th
  37. >e 
  38. >address of the function to be executed.
  39. >So you will have a runtime overhead. But keep in mind, that the percentage 
  40. of th
  41. >e 
  42. >overhead in general is very small, as the code of the virtual function needs 
  43. mor
  44. >e time 
  45. >to execute than the code for the overhead in most cases. Also the 
  46. address-lookup
  47. > is 
  48. >implemented using hash-functions in most cases.
  49.  
  50. Not correct. Overhead of "virtuality" is even less, because there is no need
  51. for hash-functions: offset in virtual table is known at the compilation
  52. time. In most cases (at list for compilers I know about) virtual function
  53. call is longe then regular by 2 - 3 CPU instruction (just extra
  54. dereferencing). It may be a littli bit more in case of multiple onheritance.
  55. -- 
  56. <<< If you received it by E-mail: it is a copy of post to the newsgroup >>>
  57. ---------------------------------------------------------------
  58. Michael Furman,                       (603)893-1109
  59. Geophysical Survey Systems, Inc.  fax:(603)889-3984
  60. 13 Klein Drive - P.O. Box 97          engr@gssi.mv.com 
  61. North Salem, NH 03073-0097            71543.1334@compuserve.com
  62. ---------------------------------------------------------------
  63.  
  64.